package com.djnt.catering.database;

import java.util.HashMap;

import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import com.djnt.catering.HanziHelper;

public class City extends PinyinColumns implements Comparable<City> {
	String mText;
	City parent;
	static final String TABLE_NAME = "city";
	public static final Uri CONTENT_URI = Uri.parse("content://"
			+ CateringProvider.AUTHORITY + "/" + TABLE_NAME);

	public static final String OWNER_ID = "owner_id";
	public static final String DEFAULT_SORT_ORDER = PINYIN;

	public City(String s) {
		// TODO Auto-generated constructor stub
		mText = s;
	}

	@Override
	public int compareTo(City another) {
		return HanziHelper.compareString(this.mText, another.mText);
	}

	public static void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
				+ " INTEGER PRIMARY KEY," + NAME + " TEXT," + OWNER_ID
				+ " INTEGER REFERENCES " + Province.TABLE_NAME + "("
				+ Province._ID + ")," + PINYIN + " TEXT," + FIRST_CHAR
				+ " TEXT," + SECOND_CHAR + " TEXT," + THIRD_CHAR + " TEXT"
				+ ");");
	}

	public static HashMap<String, String> PROJECTION_MAP = new HashMap<String, String>();
	static {
		PROJECTION_MAP.put(_ID, _ID);
		PROJECTION_MAP.put(NAME, NAME);
		PROJECTION_MAP.put(OWNER_ID, OWNER_ID);
		PROJECTION_MAP.put(PINYIN, PINYIN);
		PROJECTION_MAP.put(FIRST_CHAR, FIRST_CHAR);
		PROJECTION_MAP.put(SECOND_CHAR, SECOND_CHAR);
		PROJECTION_MAP.put(THIRD_CHAR, THIRD_CHAR);
		UriMatcherCode.addURI(TABLE_NAME, UriMatcherCode.CITY);
	}
}
